from flask import Blueprint, jsonify
from .tasks import add2
from .models import db, Message

th = Blueprint('', __name__)


@th.route('/')
def index():
    res = add2.delay("hello word")
    return jsonify(res.wait())


@th.get('/msgs')
def msg_list():
    messages = Message.query.all()
    results = []
    for message in messages:
        results.append(message.to_json())
    return jsonify(results)